import {FormSchema} from '/@/components/Table';
import {DescItem} from '/@/components/Description/index';
import {render} from '/@/utils/common/renderUtils';

export const columns = [
  {
    title: '业务类型',
    dataIndex: 'bizType',
    width: 120,
  },

  // {
  //   title: '系统内置',
  //   dataIndex: 'sysBuiltIn',
  //   customRender: ({ text }) => {
  //     return render.renderTag(text ? '是' : '否', 'green')
  //   },
  //   width: 100,
  // },

  {
    title: '限制类型',
    dataIndex: 'fileTypeLimit',
    customRender: ({ text }) => {
      if (!text) {
        return ''
      }
      const data = text.split(',')
      return render.renderTag(data, 'green')
    },
    width: 160,
  },

  {
    title: '限制大小',
    dataIndex: 'fileSizeLimit',
    width: 80,
    customRender: ({ text }) => {
      return render.renderSpan(text + ' KB')
    },
  },

  {
    title: '存储路径',
    dataIndex: 'path',
    width: 100,
  },

  {
    title: '状态',
    dataIndex: 'status',
    width: 60,
    customRender: ({ text }) => {
      let color = 'red'
      if (text === '1') {
        color = 'green'
      }
      return render.renderTag(render.renderDict(text, 'data_use_status'), color)
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createdAt',
    width: 160,
  },
  {
    title: '创建者',
    dataIndex: 'createdBy',
    width: 100,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'bizType',
    label: '业务类型',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '存储器',
    field: 'storageType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'file_storage_type',
    },
    colProps: {span: 6},
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false
  },
  {
    field: 'bizType',
    label: '业务类型',
    required: true,
    component: 'Input',
  },
  // {
  //   field: 'bucketName',
  //   label: '存储桶',
  //   required: true,
  //   component: 'Input',
  // },
  {
    label: '限制类型',
    field: 'fileTypeLimit',
    helpMessage: '为空则不限制',
    component: 'JDictSelectTag',
    componentProps: {
      mode: "multiple",
      dictCode: 'file_type',
      // stringToNumber: true
    },
  },
  {
    label: '限制大小',
    field: 'fileSizeLimit',
    helpMessage: '单位为KB',
    required: true,
    slot: 'fileSizeLimit',
    component: 'Input',
  },

  {
    label: '存储路径',
    field: 'path',
    helpMessage: '存储在服务上的文件根路径',
    required: true,
    component: 'Input',
  },

  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    defaultValue: '1',
    componentProps: {
      type: "radio",
      dictCode: 'data_use_status',
    },
  },

  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入备注',
      rows: 5,
    },
  },
];



export const formDetailSchema: DescItem[] = [
  {
    field: 'bizType',
    label: '业务类型',
  },
  {
    field: 'fileTypeLimit',
    label: '限制类型',
    render: (curVal, data) => {
      let val = []
      if (curVal) {
        val = curVal.split(',')
      }
      return render.renderTag(val, 'green')
    }
  },
  {
    field: 'fileSizeLimit',
    label: '限制大小',
    render: (curVal, data) => {
      return curVal + ' KB'
    },
  },
  {
    field: 'path',
    label: '存储路径'
  },
  {
    field: 'status',
    label: '状态',
    render: (curVal, data) => {
      let color = '#ff7f50'
      if (curVal === '1') {
        color = '#2ecc71'
      }
      return render.renderTag(render.renderDict(curVal, 'data_use_status'), color)
    },
  },
  {
    field: 'createdAt',
    label: '创建时间'
  },
  {
    field: 'createdBy',
    label: '创建者'
  },
  {
    field: 'updatedAt',
    label: '更新时间'
  },
  {
    field: 'updatedBy',
    label: '更新者'
  },
  {
    label: '备注',
    labelMinWidth: 40,
    field: 'remark',
  }
];


